home *** CD-ROM | disk | FTP | other *** search
/ BBS in a Box 5 / BBS in a Box -Volume V (BBS in a Box) (April 1992).iso / Files / Prog / M / MPWGCC (Sources).cpt / Sources / emit-rtl.c < prev    next >
Encoding:
C/C++ Source or Header  |  1990-03-15  |  40.2 KB  |  1,673 lines  |  [TEXT/MPS ]

  1. /* Emit RTL for the GNU C-Compiler expander.
  2.    Copyright (C) 1987, 1988 Free Software Foundation, Inc.
  3.    Copyright (C) 1989, 1990 Apple Computer, Inc.
  4.  
  5. This file is part of GNU CC.
  6.  
  7. GNU CC is free software; you can redistribute it and/or modify
  8. it under the terms of the GNU General Public License as published by
  9. the Free Software Foundation; either version 1, or (at your option)
  10. any later version.
  11.  
  12. GNU CC is distributed in the hope that it will be useful,
  13. but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  15. GNU General Public License for more details.
  16.  
  17. You should have received a copy of the GNU General Public License
  18. along with GNU CC; see the file COPYING.  If not, write to
  19. the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.  */
  20.  
  21.  
  22. /* Middle-to-low level generation of rtx code and insns.
  23.  
  24.    This file contains the functions `gen_rtx', `gen_reg_rtx'
  25.    and `gen_label_rtx' that are the usual ways of creating rtl
  26.    expressions for most purposes.
  27.  
  28.    It also has the functions for creating insns and linking
  29.    them in the doubly-linked chain.
  30.  
  31.    The patterns of the insns are created by machine-dependent
  32.    routines in insn-emit.c, which is generated automatically from
  33.    the machine description.  These routines use `gen_rtx' to make
  34.    the individual rtx's of the pattern; what is machine dependent
  35.    is the kind of rtx's they make and what arguments they use.  */
  36.  
  37. #include "config.h"
  38. #include <stdio.h>
  39. #include "gvarargs.h"
  40. #include "rtl.h"
  41. #include "regs.h"
  42. #include "insn-config.h"
  43. #include "real.h"
  44.  
  45. #define max(A,B) ((A) > (B) ? (A) : (B))
  46. #define min(A,B) ((A) < (B) ? (A) : (B))
  47.  
  48. /* This is reset to FIRST_PSEUDO_REGISTER at the start each function.
  49.    After rtl generation, it is 1 plus the largest register number used.  */
  50.  
  51. int reg_rtx_no = FIRST_PSEUDO_REGISTER;
  52.  
  53. /* This is *not* reset after each function.  It gives each CODE_LABEL
  54.    in the entire compilation a unique label number.  */
  55.  
  56. static int label_num = 1;
  57.  
  58. /* Value of `label_num' at start of current function.  */
  59.  
  60. static int first_label_num;
  61.  
  62. /* Nonzero means do not generate NOTEs for source line numbers.  */
  63.  
  64. static int no_line_numbers;
  65.  
  66. /* Commonly used rtx's, so that we only need space for one copy.
  67.    These are initialized once for the entire compilation.
  68.    All of these except perhaps fconst0_rtx and dconst0_rtx
  69.    are unique; no other rtx-object will be equal to any of these.  */
  70.  
  71. rtx pc_rtx;            /* (PC) */
  72. rtx cc0_rtx;            /* (CC0) */
  73. rtx cc1_rtx;            /* (CC1) (not actually used nowadays) */
  74. rtx const0_rtx;            /* (CONST_INT 0) */
  75. rtx const1_rtx;            /* (CONST_INT 1) */
  76. rtx fconst0_rtx;        /* (CONST_DOUBLE:SF 0) */
  77. rtx dconst0_rtx;        /* (CONST_DOUBLE:DF 0) */
  78. #ifdef APPLE_C
  79. /* Zero in extended mode is still a CONST_DOUBLE rtx. */
  80. rtx ldconst0_rtx;        /* (CONST_DOUBLE:XF 0) */
  81. #endif /* APPLE_C */
  82.  
  83. /* All references to the following fixed hard registers go through
  84.    these unique rtl objects.  On machines where the frame-pointer and
  85.    arg-pointer are the same register, they use the same unique object.
  86.  
  87.    After register allocation, other rtl objects which used to be pseudo-regs
  88.    may be clobbered to refer to the frame-pointer register.
  89.    But references that were originally to the frame-pointer can be
  90.    distinguished from the others because they contain frame_pointer_rtx.
  91.  
  92.    In an inline procedure, the stack and frame pointer rtxs may not be
  93.    used for anything else.  */
  94. rtx stack_pointer_rtx;        /* (REG:Pmode STACK_POINTER_REGNUM) */
  95. rtx frame_pointer_rtx;        /* (REG:Pmode FRAME_POINTER_REGNUM) */
  96. rtx arg_pointer_rtx;        /* (REG:Pmode ARG_POINTER_REGNUM) */
  97. rtx struct_value_rtx;        /* (REG:Pmode STRUCT_VALUE_REGNUM) */
  98. rtx struct_value_incoming_rtx;    /* (REG:Pmode STRUCT_VALUE_INCOMING_REGNUM) */
  99. rtx static_chain_rtx;        /* (REG:Pmode STATIC_CHAIN_REGNUM) */
  100. rtx static_chain_incoming_rtx;    /* (REG:Pmode STATIC_CHAIN_INCOMING_REGNUM) */
  101.  
  102. /* The ends of the doubly-linked chain of rtl for the current function.
  103.    Both are reset to null at the start of rtl generation for the function.
  104.    
  105.    start_sequence saves both of these on `sequence_stack' and then
  106.    starts a new, nested sequence of insns.  */
  107.  
  108. static rtx first_insn = NULL;
  109. static rtx last_insn = NULL;
  110.  
  111. /* Stack of pending (incomplete) sequences saved by `start_sequence'.
  112.    This looks like
  113.    (INSN_LIST saved-first-insn
  114.               (INSN_LIST saved-last-insn ...more saved sequences...)).
  115.    The main insn-chain is saved in the last two links of the chain,
  116.    unless the chain is empty.  */
  117.  
  118. rtx sequence_stack = 0;
  119.  
  120. /* INSN_UID for next insn emitted.
  121.    Reset to 1 for each function compiled.  */
  122.  
  123. static int cur_insn_uid = 1;
  124.  
  125. /* Line number and source file of the last line-number NOTE emitted.
  126.    This is used to avoid generating duplicates.  */
  127.  
  128. static int last_linenum = 0;
  129. static char *last_filename = 0;
  130.  
  131. /* A vector indexed by pseudo reg number.  The allocated length
  132.    of this vector is regno_pointer_flag_length.  Since this
  133.    vector is needed during the expansion phase when the total
  134.    number of registers in the function is not yet known,
  135.    it is copied and made bigger when necessary.  */
  136.  
  137. char *regno_pointer_flag;
  138. int regno_pointer_flag_length;
  139.  
  140. /* Indexed by pseudo register number, gives the rtx for that pseudo.
  141.    Allocated in parallel with regno_pointer_flag.  */
  142.  
  143. rtx *regno_reg_rtx;
  144.  
  145. /* Filename and line number of last line-number note,
  146.    whether we actually emitted it or not.  */
  147. extern char *emit_filename;
  148. extern int emit_lineno;
  149.  
  150. rtx change_address ();
  151.  
  152. /* rtx gen_rtx (code, mode, [element1, ..., elementn])
  153. **
  154. **        This routine generates an RTX of the size specified by
  155. **    <code>, which is an RTX code.   The RTX structure is initialized
  156. **    from the arguments <element1> through <elementn>, which are
  157. **    interpreted according to the specific RTX type's format.   The
  158. **    special machine mode associated with the rtx (if any) is specified
  159. **    in <mode>.
  160. **
  161. **        gen_rtx() can be invoked in a way which resembles the lisp-like
  162. **    rtx it will generate.   For example, the following rtx structure:
  163. **
  164. **          (plus:QI (mem:QI (reg:SI 1))
  165. **               (mem:QI (plusw:SI (reg:SI 2) (reg:SI 3))))
  166. **
  167. **        ...would be generated by the following C code:
  168. **
  169. **            gen_rtx (PLUS, QImode,
  170. **            gen_rtx (MEM, QImode,
  171. **            gen_rtx (REG, SImode, 1)),
  172. **            gen_rtx (MEM, QImode,
  173. **            gen_rtx (PLUS, SImode,
  174. **                gen_rtx (REG, SImode, 2),
  175. **                gen_rtx (REG, SImode, 3)))),
  176. */
  177.  
  178. /*VARARGS2*/
  179. rtx
  180. #ifdef APPLE_HAX
  181. gen_rtx (code, mode)
  182.   enum rtx_code code;
  183.   enum machine_mode mode;
  184. {
  185.   va_list p;
  186. #else
  187. gen_rtx (va_alist)
  188.      va_dcl
  189. {
  190.   va_list p;
  191.   enum rtx_code code;
  192.   enum machine_mode mode;
  193. #endif
  194.   register int i;        /* Array indices...            */
  195.   register char *fmt;        /* Current rtx's format...        */
  196.   register rtx rt_val;        /* RTX to return to caller...        */
  197.  
  198. #ifdef APPLE_HAX
  199.   va_start (p, mode);
  200. #else
  201.   va_start (p);
  202.   code = va_arg (p, enum rtx_code);
  203.   mode = va_arg (p, enum machine_mode);
  204. #endif
  205.  
  206.   if (code == CONST_INT)
  207.     {
  208.       int arg = va_arg (p, int);
  209.       if (arg == 0)
  210.     return const0_rtx;
  211.       if (arg == 1)
  212.     return const1_rtx;
  213.       rt_val = rtx_alloc (code);
  214.       INTVAL (rt_val) = arg;
  215.     }
  216.   else
  217.     {
  218.       rt_val = rtx_alloc (code);    /* Allocate the storage space.  */
  219.       rt_val->mode = mode;        /* Store the machine mode...  */
  220.  
  221.       fmt = GET_RTX_FORMAT (code);    /* Find the right format...  */
  222.       for (i = 0; i < GET_RTX_LENGTH (code); i++)
  223.     {
  224.       switch (*fmt++)
  225.         {
  226.         case '0':        /* Unused field.  */
  227.           break;
  228.  
  229.         case 'i':        /* An integer?  */
  230.           XINT (rt_val, i) = va_arg (p, int);
  231.           break;
  232.  
  233.         case 's':        /* A string?  */
  234.           XSTR (rt_val, i) = va_arg (p, char *);
  235.           break;
  236.  
  237.         case 'e':        /* An expression?  */
  238.         case 'u':        /* An insn?  Same except when printing.  */
  239.           XEXP (rt_val, i) = va_arg (p, rtx);
  240.           break;
  241.  
  242.         case 'E':        /* An RTX vector?  */
  243.           XVEC (rt_val, i) = va_arg (p, rtvec);
  244.           break;
  245.  
  246.         default:
  247.           abort();
  248.         }
  249.     }
  250.     }
  251.   va_end (p);
  252.   return rt_val;        /* Return the new RTX...        */
  253. }
  254.  
  255. /* gen_rtvec (n, [rt1, ..., rtn])
  256. **
  257. **        This routine creates an rtvec and stores within it the
  258. **    pointers to rtx's which are its arguments.
  259. */
  260.  
  261. /*VARARGS1*/
  262. rtvec
  263. #ifdef APPLE_HAX
  264. gen_rtvec (n)
  265.   int n;
  266. {
  267.   int i;
  268.   va_list p;
  269. #else
  270. gen_rtvec (va_alist)
  271.      va_dcl
  272. {
  273.   int n, i;
  274.   va_list p;
  275. #endif
  276.   rtx *vector;
  277.  
  278. #ifdef APPLE_HAX
  279.   va_start (p, n);
  280. #else
  281.   va_start (p);
  282.   n = va_arg (p, int);
  283. #endif
  284.  
  285.   if (n == 0)
  286.     return NULL_RTVEC;        /* Don't allocate an empty rtvec...    */
  287.  
  288.   vector = (rtx *) alloca (n * sizeof (rtx));
  289.   for (i = 0; i < n; i++)
  290.     vector[i] = va_arg (p, rtx);
  291.   va_end (p);
  292.  
  293.   return gen_rtvec_v (n, vector);
  294. }
  295.  
  296. rtvec
  297. gen_rtvec_v (n, argp)
  298.      int n;
  299.      rtx *argp;
  300. {
  301.   register int i;
  302.   register rtvec rt_val;
  303.  
  304.   if (n == 0)
  305.     return NULL_RTVEC;        /* Don't allocate an empty rtvec...    */
  306.  
  307.   rt_val = rtvec_alloc (n);    /* Allocate an rtvec...            */
  308.  
  309.   for (i = 0; i < n; i++)
  310.     rt_val->elem[i].rtx = *argp++;
  311.  
  312.   return rt_val;
  313. }
  314.  
  315. /* Generate a REG rtx for a new pseudo register of mode MODE.
  316.    This pseudo is assigned the next sequential register number.  */
  317.  
  318. rtx
  319. gen_reg_rtx (mode)
  320.      enum machine_mode mode;
  321. {
  322.   register rtx val;
  323.  
  324.   /* Make sure regno_pointer_flag and regno_reg_rtx are large
  325.      enough to have an element for this pseudo reg number.  */
  326.  
  327.   if (reg_rtx_no == regno_pointer_flag_length)
  328.     {
  329.       rtx *new1;
  330.       char *new =
  331.     (char *) oballoc (regno_pointer_flag_length * 2);
  332.       bzero (new, regno_pointer_flag_length * 2);
  333.       bcopy (regno_pointer_flag, new, regno_pointer_flag_length);
  334.       regno_pointer_flag = new;
  335.  
  336.       new1 = (rtx *) oballoc (regno_pointer_flag_length * 2 * sizeof (rtx));
  337.       bzero (new1, regno_pointer_flag_length * 2 * sizeof (rtx));
  338.       bcopy (regno_reg_rtx, new1, regno_pointer_flag_length * sizeof (rtx));
  339.       regno_reg_rtx = new1;
  340.  
  341.       regno_pointer_flag_length *= 2;
  342.     }
  343.  
  344.   val = gen_rtx (REG, mode, reg_rtx_no);
  345.   regno_reg_rtx[reg_rtx_no++] = val;
  346.   return val;
  347. }
  348.  
  349. /* Identify REG as a probable pointer register.  */
  350.  
  351. void
  352. mark_reg_pointer (reg)
  353.      rtx reg;
  354. {
  355.   REGNO_POINTER_FLAG (REGNO (reg)) = 1;
  356. }
  357.  
  358. /* Return 1 plus largest pseudo reg number used in the current function.  */
  359.  
  360. int
  361. max_reg_num ()
  362. {
  363.   return reg_rtx_no;
  364. }
  365.  
  366. /* Return 1 + the largest label number used so far.  */
  367.  
  368. int
  369. max_label_num ()
  370. {
  371.   return label_num;
  372. }
  373.  
  374. /* Return first label number used in this function (if any were used).  */
  375.  
  376. int
  377. get_first_label_num ()
  378. {
  379.   return first_label_num;
  380. }
  381.  
  382. /* Assuming that X is an rtx (MEM, REG or SUBREG) for a fixed-point number,
  383.    return a MEM or SUBREG rtx that refers to the least-significant part of X.
  384.    MODE specifies how big a part of X to return;
  385.    it must not be larger than a word.
  386.    If X is a MEM whose address is a QUEUED, the value may be so also.  */
  387.  
  388. rtx
  389. gen_lowpart (mode, x)
  390.      enum machine_mode mode;
  391.      register rtx x;
  392. {
  393.   /* This case loses if X is a subreg.  To catch bugs early,
  394.      complain if an invalid MODE is used even in other cases.  */
  395.   if (GET_MODE_SIZE (mode) > UNITS_PER_WORD
  396.       && GET_MODE_SIZE (mode) != GET_MODE_UNIT_SIZE (GET_MODE (x)))
  397.     abort ();
  398.   if (GET_MODE (x) == mode)
  399.     return x;
  400.   if (GET_CODE (x) == CONST_INT)
  401.     return gen_rtx (CONST_INT, VOIDmode, INTVAL (x) & GET_MODE_MASK (mode));
  402.   if (GET_CODE (x) == CONST_DOUBLE)
  403. /* In version 1.37, try this: */
  404. /*  if (GET_MODE_CLASS (GET_MODE (x)) == MODE_FLOAT) abort (); */
  405.     /* Assume it's an int, so ..._LOW means the low-order word.  */
  406.     return gen_rtx (CONST_INT, VOIDmode,
  407.             CONST_DOUBLE_LOW (x) & GET_MODE_MASK (mode));
  408.   if (GET_CODE (x) == MEM)
  409.     {
  410.       register int offset = 0;
  411. #ifdef WORDS_BIG_ENDIAN
  412.       offset = (max (GET_MODE_SIZE (GET_MODE (x)), UNITS_PER_WORD)
  413.         - max (GET_MODE_SIZE (mode), UNITS_PER_WORD));
  414. #endif
  415. #ifdef BYTES_BIG_ENDIAN
  416.       /* Adjust the address so that the address-after-the-data
  417.      is unchanged.  */
  418.       offset -= (min (UNITS_PER_WORD, GET_MODE_SIZE (mode))
  419.          - min (UNITS_PER_WORD, GET_MODE_SIZE (GET_MODE (x))));
  420. #endif
  421.       return change_address (x, mode, plus_constant (XEXP (x, 0), offset));
  422.     }
  423.   else if (GET_CODE (x) == SUBREG)
  424.     return (GET_MODE (SUBREG_REG (x)) == mode && SUBREG_WORD (x) == 0
  425.         ? SUBREG_REG (x)
  426.         : gen_rtx (SUBREG, mode, SUBREG_REG (x), SUBREG_WORD (x)));
  427.   else if (GET_CODE (x) == REG)
  428.     {
  429. #ifdef WORDS_BIG_ENDIAN
  430.       if (GET_MODE_SIZE (GET_MODE (x)) > UNITS_PER_WORD)
  431.     {
  432.       return gen_rtx (SUBREG, mode, x,
  433.               ((GET_MODE_SIZE (GET_MODE (x))
  434.                 - max (GET_MODE_SIZE (mode), UNITS_PER_WORD))
  435.                / UNITS_PER_WORD));
  436.     }
  437. #endif
  438.       return gen_rtx (SUBREG, mode, x, 0);
  439.     }
  440.   else
  441.     abort ();
  442. }
  443.  
  444. /* Like `gen_lowpart', but refer to the most significant part.  */
  445.  
  446. rtx
  447. gen_highpart (mode, x)
  448.      enum machine_mode mode;
  449.      register rtx x;
  450. {
  451.   if (GET_CODE (x) == MEM)
  452.     {
  453.       register int offset = 0;
  454. #ifndef WORDS_BIG_ENDIAN
  455.       offset = (max (GET_MODE_SIZE (GET_MODE (x)), UNITS_PER_WORD)
  456.         - max (GET_MODE_SIZE (mode), UNITS_PER_WORD));
  457. #endif
  458. #ifndef BYTES_BIG_ENDIAN
  459.       if (GET_MODE_SIZE (mode) < UNITS_PER_WORD)
  460.     offset -= (GET_MODE_SIZE (mode)
  461.            - min (UNITS_PER_WORD,
  462.               GET_MODE_SIZE (GET_MODE (x))));
  463. #endif
  464.       return change_address (x, mode, plus_constant (XEXP (x, 0), offset));
  465.     }
  466.   else if (GET_CODE (x) == REG)
  467.     {
  468. #ifndef WORDS_BIG_ENDIAN
  469.       if (GET_MODE_SIZE (GET_MODE (x)) > UNITS_PER_WORD)
  470.     {
  471.       return gen_rtx (SUBREG, mode, x,
  472.               ((GET_MODE_SIZE (GET_MODE (x))
  473.                 - max (GET_MODE_SIZE (mode), UNITS_PER_WORD))
  474.                / UNITS_PER_WORD));
  475.     }
  476. #endif
  477.       return gen_rtx (SUBREG, mode, x, 0);
  478.     }
  479.   else
  480.     abort ();
  481. }
  482.  
  483. /* Return 1 iff X, assumed to be a SUBREG,
  484.    refers to the least significant part of its containing reg.
  485.    If X is not a SUBREG, always return 1 (it is its own low part!).  */
  486.  
  487. int
  488. subreg_lowpart_p (x)
  489.      rtx x;
  490. {
  491.   if (GET_CODE (x) != SUBREG)
  492.     return 1;
  493. #ifdef WORDS_BIG_ENDIAN
  494.   if (GET_MODE_SIZE (GET_MODE (x)) > UNITS_PER_WORD)
  495.     {
  496.       register enum machine_mode mode = GET_MODE (SUBREG_REG (x));
  497.       return (SUBREG_WORD (x)
  498.           == ((GET_MODE_SIZE (GET_MODE (x))
  499.            - max (GET_MODE_SIZE (mode), UNITS_PER_WORD))
  500.           / UNITS_PER_WORD));
  501.     }
  502. #endif 
  503.   return SUBREG_WORD (x) == 0;
  504. }
  505.  
  506. /* Return a memory reference like MEMREF, but with its mode changed
  507.    to MODE and its address changed to ADDR.
  508.    (VOIDmode means don't change the mode.
  509.    NULL for ADDR means don't change the address.)  */
  510.  
  511. rtx
  512. change_address (memref, mode, addr)
  513.      rtx memref;
  514.      enum machine_mode mode;
  515.      rtx addr;
  516. {
  517.   rtx new;
  518.  
  519.   if (GET_CODE (memref) != MEM)
  520.     abort ();
  521.   if (mode == VOIDmode)
  522.     mode = GET_MODE (memref);
  523.   if (addr == 0)
  524.     addr = XEXP (memref, 0);
  525.  
  526.   new = gen_rtx (MEM, mode, memory_address (mode, addr));
  527.   MEM_VOLATILE_P (new) = MEM_VOLATILE_P (memref);
  528.   RTX_UNCHANGING_P (new) = RTX_UNCHANGING_P (memref);
  529.   MEM_IN_STRUCT_P (new) = MEM_IN_STRUCT_P (memref);
  530.   return new;
  531. }
  532.  
  533. /* Return a newly created CODE_LABEL rtx with a unique label number.  */
  534.  
  535. rtx
  536. gen_label_rtx ()
  537. {
  538.   register rtx label = gen_rtx (CODE_LABEL, VOIDmode, 0, 0, 0, label_num++);
  539.   LABEL_NUSES (label) = 0;
  540.   return label;
  541. }
  542.  
  543. /* For procedure integration.  */
  544.  
  545. /* Return a newly created INLINE_HEADER rtx.  Should allocate this
  546.    from a permanent obstack when the opportunity arises.  */
  547.  
  548. rtx
  549. gen_inline_header_rtx (insn, last_insn,
  550.                first_labelno, last_labelno,
  551.                max_parm_regnum, max_regnum, args_size,
  552.                stack_slots)
  553.      rtx insn, last_insn;
  554.      int first_labelno, last_labelno, max_parm_regnum, max_regnum, args_size;
  555.      rtx stack_slots;
  556. {
  557.   rtx header = gen_rtx (INLINE_HEADER, VOIDmode,
  558.             cur_insn_uid++, NULL,
  559.             insn, last_insn,
  560.             first_labelno, last_labelno,
  561.             max_parm_regnum, max_regnum, args_size, stack_slots);
  562.   return header;
  563. }
  564.  
  565. /* Install new pointers to the first and last insns in the chain.
  566.    Used for an inline-procedure after copying the insn chain.  */
  567.  
  568. void
  569. set_new_first_and_last_insn (first, last)
  570.      rtx first, last;
  571. {
  572.   first_insn = first;
  573.   last_insn = last;
  574. }
  575.  
  576. /* Go through all the RTL insn bodies and copy any invalid shared structure.
  577.    It does not work to do this twice, because the mark bits set here
  578.    are not cleared afterwards.  */
  579.  
  580. static int unshare_copies = 0;    /* Count rtx's that were copied.  */
  581.  
  582. static rtx copy_rtx_if_shared ();
  583.  
  584. void
  585. unshare_all_rtl (insn)
  586.      register rtx insn;
  587. {
  588.   extern rtx stack_slot_list;
  589.  
  590.   for (; insn; insn = NEXT_INSN (insn))
  591.     if (GET_CODE (insn) == INSN || GET_CODE (insn) == JUMP_INSN
  592.     || GET_CODE (insn) == CALL_INSN)
  593.       {
  594.     PATTERN (insn) = copy_rtx_if_shared (PATTERN (insn));
  595.     REG_NOTES (insn) = copy_rtx_if_shared (REG_NOTES (insn));
  596.     LOG_LINKS (insn) = copy_rtx_if_shared (LOG_LINKS (insn));
  597.       }
  598.  
  599.   /* Make sure the addresses of stack slots are not shared
  600.      with anything in the insn chain.  That could happen if
  601.      the stack slot is referenced only by its address.  */
  602.   copy_rtx_if_shared (stack_slot_list);
  603. }
  604.  
  605. /* Mark ORIG as in use, and return a copy of it if it was already in use.
  606.    Recursively does the same for subexpressions.  */
  607.  
  608. static rtx
  609. copy_rtx_if_shared (orig)
  610.      rtx orig;
  611. {
  612.   register rtx x = orig;
  613.   register int i;
  614.   register enum rtx_code code;
  615.   register char *format_ptr;
  616.   int copied = 0;
  617.  
  618.   if (x == 0)
  619.     return 0;
  620.  
  621.   code = GET_CODE (x);
  622.  
  623.   /* These types may be freely shared.  */
  624.  
  625.   switch (code)
  626.     {
  627.     case REG:
  628.     case QUEUED:
  629.     case CONST_INT:
  630.     case CONST_DOUBLE:
  631.     case SYMBOL_REF:
  632.     case CODE_LABEL:
  633.     case PC:
  634.     case CC0:
  635.       return x;
  636.  
  637.     case INSN:
  638.     case JUMP_INSN:
  639.     case CALL_INSN:
  640.     case NOTE:
  641.     case LABEL_REF:
  642.     case BARRIER:
  643.       /* The chain of insns is not being copied.  */
  644.       return x;
  645.  
  646.     case MEM:
  647.       /* A MEM is allowed to be shared if its address is constant
  648.      or is a constant plus one of the special registers.  */
  649.       if (CONSTANT_ADDRESS_P (XEXP (x, 0)))
  650.     return x;
  651.       if (GET_CODE (XEXP (x, 0)) == PLUS
  652.       && (XEXP (XEXP (x, 0), 0) == frame_pointer_rtx
  653.           || XEXP (XEXP (x, 0), 0) == arg_pointer_rtx)
  654.       && CONSTANT_ADDRESS_P (XEXP (XEXP (x, 0), 1)))
  655.     {
  656.       /* This MEM can appear in more than one place,
  657.          but its address better not be shared with anything else.  */
  658.       if (! x->used)
  659.         XEXP (x, 0) = copy_rtx_if_shared (XEXP (x, 0));
  660.       x->used = 1;
  661.       return x;
  662.     }
  663.       if (XEXP (x, 0) == frame_pointer_rtx
  664.       || XEXP (x, 0) == arg_pointer_rtx)
  665.     return x;
  666.     }
  667.  
  668.   /* This rtx may not be shared.  If it has already been seen,
  669.      replace it with a copy of itself.  */
  670.  
  671.   if (x->used)
  672.     {
  673.       register rtx copy;
  674.  
  675.       unshare_copies++;
  676.  
  677.       copy = rtx_alloc (code);
  678.       bcopy (x, copy, (sizeof (*copy) - sizeof (copy->fld)
  679.                + sizeof (copy->fld[0]) * GET_RTX_LENGTH (code)));
  680.       x = copy;
  681.       copied = 1;
  682.     }
  683.   x->used = 1;
  684.  
  685.   /* Now scan the subexpressions recursively.
  686.      We can store any replaced subexpressions directly into X
  687.      since we know X is not shared!  Any vectors in X
  688.      must be copied if X was copied.  */
  689.  
  690.   format_ptr = GET_RTX_FORMAT (code);
  691.  
  692.   for (i = 0; i < GET_RTX_LENGTH (code); i++)
  693.     {
  694.       switch (*format_ptr++)
  695.     {
  696.     case 'e':
  697.       XEXP (x, i) = copy_rtx_if_shared (XEXP (x, i));
  698.       break;
  699.  
  700.     case 'E':
  701.       if (XVEC (x, i) != NULL)
  702.         {
  703.           register int j;
  704.  
  705.           if (copied)
  706.         XVEC (x, i) = gen_rtvec_v (XVECLEN (x, i), &XVECEXP (x, i, 0));
  707.           for (j = 0; j < XVECLEN (x, i); j++)
  708.         XVECEXP (x, i, j)
  709.           = copy_rtx_if_shared (XVECEXP (x, i, j));
  710.         }
  711.       break;
  712.     }
  713.     }
  714.   return x;
  715. }
  716.  
  717. /* Copy X if necessary so that it won't be altered by changes in OTHER.
  718.    Return X or the rtx for the pseudo reg the value of X was copied into.
  719.    OTHER must be valid as a SET_DEST.  */
  720.  
  721. rtx
  722. make_safe_from (x, other)
  723.      rtx x, other;
  724. {
  725.   while (1)
  726.     switch (GET_CODE (other))
  727.       {
  728.       case SUBREG:
  729.     other = SUBREG_REG (other);
  730.     break;
  731.       case STRICT_LOW_PART:
  732.       case SIGN_EXTEND:
  733.       case ZERO_EXTEND:
  734.     other = XEXP (other, 0);
  735.     break;
  736.       default:
  737.     goto done;
  738.       }
  739.  done:
  740.   if ((GET_CODE (other) == MEM
  741.        && ! CONSTANT_P (x)
  742.        && GET_CODE (x) != CONST_DOUBLE
  743.        && GET_CODE (x) != REG
  744.        && GET_CODE (x) != SUBREG)
  745.       || (GET_CODE (other) == REG
  746.       && (REGNO (other) < FIRST_PSEUDO_REGISTER
  747.           || reg_mentioned_p (other, x))))
  748.     {
  749.       rtx temp = gen_reg_rtx (GET_MODE (x));
  750.       emit_move_insn (temp, x);
  751.       return temp;
  752.     }
  753.   return x;
  754. }
  755.  
  756. /* Emission of insns (adding them to the doubly-linked list).  */
  757.  
  758. /* Return the first insn of the current sequence or current function.  */
  759.  
  760. rtx
  761. get_insns ()
  762. {
  763.   return first_insn;
  764. }
  765.  
  766. /* Return the last insn emitted in current sequence or current function.  */
  767.  
  768. rtx
  769. get_last_insn ()
  770. {
  771.   return last_insn;
  772. }
  773.  
  774. /* Specify a new insn as the last in the chain.  */
  775.  
  776. void
  777. set_last_insn (insn)
  778.      rtx insn;
  779. {
  780.   if (NEXT_INSN (insn) != 0)
  781.     abort ();
  782.   last_insn = insn;
  783. }
  784.  
  785. /* Return a number larger than any instruction's uid in this function.  */
  786.  
  787. int
  788. get_max_uid ()
  789. {
  790.   return cur_insn_uid;
  791. }
  792.  
  793. rtx
  794. next_insn (insn)
  795.      rtx insn;
  796. {
  797.   if (insn) return NEXT_INSN (insn);
  798.   return 0;
  799. }
  800.  
  801. rtx
  802. previous_insn (insn)
  803.      rtx insn;
  804. {
  805.   if (insn) return PREV_INSN (insn);
  806.   return 0;
  807. }
  808.  
  809. /* Make and return an INSN rtx, initializing all its slots.
  810.    Store PATTERN in the pattern slots.
  811.    PAT_FORMALS is an idea that never really went anywhere.  */
  812.  
  813. static rtx
  814. make_insn_raw (pattern, pat_formals)
  815.      rtx pattern;
  816.      rtvec pat_formals;
  817. {
  818.   register rtx insn;
  819.  
  820.   insn = rtx_alloc(INSN);
  821.   INSN_UID(insn) = cur_insn_uid++;
  822.  
  823.   PATTERN (insn) = pattern;
  824.   INSN_CODE (insn) = -1;
  825.   LOG_LINKS(insn) = NULL;
  826.   REG_NOTES(insn) = NULL;
  827.  
  828.   return insn;
  829. }
  830.  
  831. /* Like `make_insn' but make a JUMP_INSN instead of an insn.  */
  832.  
  833. static rtx
  834. make_jump_insn_raw (pattern, pat_formals)
  835.      rtx pattern;
  836.      rtvec pat_formals;
  837. {
  838.   register rtx insn;
  839.  
  840.   insn = rtx_alloc(JUMP_INSN);
  841.   INSN_UID(insn) = cur_insn_uid++;
  842.  
  843.   PATTERN (insn) = pattern;
  844.   INSN_CODE (insn) = -1;
  845.   LOG_LINKS(insn) = NULL;
  846.   REG_NOTES(insn) = NULL;
  847.   JUMP_LABEL(insn) = NULL;
  848.  
  849.   return insn;
  850. }
  851.  
  852. /* Add INSN to the end of the doubly-linked list.
  853.    INSN may be an INSN, JUMP_INSN, CALL_INSN, CODE_LABEL, BARRIER or NOTE.  */
  854.  
  855. static void
  856. add_insn (insn)
  857.      register rtx insn;
  858. {
  859.   PREV_INSN (insn) = last_insn;
  860.   NEXT_INSN (insn) = 0;
  861.  
  862.   if (NULL != last_insn)
  863.     NEXT_INSN (last_insn) = insn;
  864.  
  865.   if (NULL == first_insn)
  866.     first_insn = insn;
  867.  
  868.   last_insn = insn;
  869. }
  870.  
  871. /* Add INSN, an rtx of code INSN, into the doubly-linked list
  872.    after insn AFTER.  */
  873.  
  874. static void
  875. add_insn_after (insn, after)
  876.      rtx insn, after;
  877. {
  878.   NEXT_INSN (insn) = NEXT_INSN (after);
  879.   PREV_INSN (insn) = after;
  880.  
  881.   if (NEXT_INSN (insn))
  882.     PREV_INSN (NEXT_INSN (insn)) = insn;
  883.   else if (last_insn == after)
  884.     last_insn = insn;
  885.   else
  886.     {
  887.       rtx stack = sequence_stack;
  888.       /* Scan all pending sequences too.  */
  889.       for (; stack; stack = XEXP (XEXP (stack, 1), 1))
  890.     if (after == XEXP (XEXP (stack, 1), 0))
  891.       XEXP (XEXP (stack, 1), 0) = insn;
  892.     }
  893.  
  894.   NEXT_INSN (after) = insn;
  895. }
  896.  
  897. /* Delete all insns made since FROM.
  898.    FROM becomes the new last instruction.  */
  899.  
  900. void
  901. delete_insns_since (from)
  902.      rtx from;
  903. {
  904.   if (from == 0)
  905.     first_insn = 0;
  906.   else
  907.     NEXT_INSN (from) = 0;
  908.   last_insn = from;
  909. }
  910.  
  911. /* Move a consecutive bunch of insns to a different place in the chain.
  912.    The insns to be moved are those between FROM and TO.
  913.    They are moved to a new position after the insn AFTER.  */
  914.  
  915. void
  916. reorder_insns (from, to, after)
  917.      rtx from, to, after;
  918. {
  919.   /* Splice this bunch out of where it is now.  */
  920.   if (PREV_INSN (from))
  921.     NEXT_INSN (PREV_INSN (from)) = NEXT_INSN (to);
  922.   if (NEXT_INSN (to))
  923.     PREV_INSN (NEXT_INSN (to)) = PREV_INSN (from);
  924.   if (last_insn == to)
  925.     last_insn = PREV_INSN (from);
  926.   if (first_insn == from)
  927.     first_insn = NEXT_INSN (to);
  928.  
  929.   /* Make the new neighbors point to it and it to them.  */
  930.   if (NEXT_INSN (after))
  931.     {
  932.       PREV_INSN (NEXT_INSN (after)) = to;
  933.       NEXT_INSN (to) = NEXT_INSN (after);
  934.     }
  935.   PREV_INSN (from) = after;
  936.   NEXT_INSN (after) = from;
  937.   if (after == last_insn)
  938.     last_insn = to;
  939. }
  940.  
  941. /* Emit an insn of given code and pattern
  942.    at a specified place within the doubly-linked list.  */
  943.  
  944. /* Make an instruction with body PATTERN
  945.    and output it before the instruction BEFORE.  */
  946.  
  947. rtx
  948. emit_insn_before (pattern, before)
  949.      register rtx pattern, before;
  950. {
  951.   register rtx insn;
  952.  
  953.   if (GET_CODE (pattern) == SEQUENCE)
  954.     {
  955.       register int i;
  956.       /* For an empty sequence, emit nothing.  */
  957.       if (XVEC (pattern, 0))
  958.     for (i = 0; i < XVECLEN (pattern, 0); i++)
  959.       add_insn_after (XVECEXP (pattern, 0, i), PREV_INSN (before));
  960.       return PREV_INSN (before);
  961.     }
  962.  
  963.   insn = make_insn_raw (pattern, 0);
  964.  
  965.   PREV_INSN (insn) = PREV_INSN (before);
  966.   NEXT_INSN (insn) = before;
  967.  
  968.   if (PREV_INSN (insn))
  969.     NEXT_INSN (PREV_INSN (insn)) = insn;
  970.   else
  971.     first_insn = insn;
  972.   PREV_INSN (before) = insn;
  973.  
  974.   return insn;
  975. }
  976.  
  977. /* Make an instruction with body PATTERN and code JUMP_INSN
  978.    and output it before the instruction BEFORE.  */
  979.  
  980. rtx
  981. emit_jump_insn_before (pattern, before)
  982.      register rtx pattern, before;
  983. {
  984.   register rtx insn = make_jump_insn_raw (pattern, 0);
  985.  
  986.   PREV_INSN (insn) = PREV_INSN (before);
  987.   NEXT_INSN (insn) = before;
  988.  
  989.   if (PREV_INSN (insn))
  990.     NEXT_INSN (PREV_INSN (insn)) = insn;
  991.   else
  992.     first_insn = insn;
  993.   PREV_INSN (before) = insn;
  994.  
  995.   return insn;
  996. }
  997.  
  998. /* Make an instruction with body PATTERN and code CALL_INSN
  999.    and output it before the instruction BEFORE.  */
  1000.  
  1001. rtx
  1002. emit_call_insn_before (pattern, before)
  1003.      register rtx pattern, before;
  1004. {
  1005.   rtx insn = emit_insn_before (pattern, before);
  1006.   PUT_CODE (insn, CALL_INSN);
  1007.   return insn;
  1008. }
  1009.  
  1010. /* Make an insn of code INSN with body PATTERN
  1011.    and output it after the insn AFTER.  */
  1012.  
  1013. rtx
  1014. emit_insn_after (pattern, after)
  1015.      register rtx pattern, after;
  1016. {
  1017.   if (GET_CODE (pattern) == SEQUENCE)
  1018.     {
  1019.       register int i;
  1020.       /* For an empty sequence, emit nothing.  */
  1021.       if (XVEC (pattern, 0))
  1022.     for (i = 0; i < XVECLEN (pattern, 0); i++)
  1023.       {
  1024.         add_insn_after (XVECEXP (pattern, 0, i), after);
  1025.         after = NEXT_INSN (after);
  1026.       }
  1027.       return after;
  1028.     }
  1029.   else
  1030.     {
  1031.       register rtx insn = make_insn_raw (pattern, 0);
  1032.       add_insn_after (insn, after);
  1033.       return insn;
  1034.     }
  1035. }
  1036.  
  1037. /* Make an insn of code JUMP_INSN with body PATTERN
  1038.    and output it after the insn AFTER.  */
  1039.  
  1040. rtx
  1041. emit_jump_insn_after (pattern, after)
  1042.      register rtx pattern, after;
  1043. {
  1044.   register rtx insn = make_jump_insn_raw (pattern, 0);
  1045.  
  1046.   add_insn_after (insn, after);
  1047.   return insn;
  1048. }
  1049.  
  1050. /* Make an insn of code BARRIER
  1051.    and output it after the insn AFTER.  */
  1052.  
  1053. rtx
  1054. emit_barrier_after (after)
  1055.      register rtx after;
  1056. {
  1057.   register rtx insn = rtx_alloc (BARRIER);
  1058.  
  1059.   INSN_UID (insn) = cur_insn_uid++;
  1060.  
  1061.   add_insn_after (insn, after);
  1062.   return insn;
  1063. }
  1064.  
  1065. /* Emit the label LABEL after the insn AFTER.  */
  1066.  
  1067. void
  1068. emit_label_after (label, after)
  1069.      rtx label, after;
  1070. {
  1071.   /* This can be called twice for the same label
  1072.      as a result of the confusion that follows a syntax error!
  1073.      So make it harmless.  */
  1074.   if (INSN_UID (label) == 0)
  1075.     {
  1076.       INSN_UID (label) = cur_insn_uid++;
  1077.       add_insn_after (label, after);
  1078.     }
  1079. }
  1080.  
  1081. /* Emit a note of subtype SUBTYPE after the insn AFTER.  */
  1082.  
  1083. void
  1084. emit_note_after (subtype, after)
  1085.      int subtype;
  1086.      rtx after;
  1087. {
  1088.   register rtx note = rtx_alloc (NOTE);
  1089.   INSN_UID (note) = cur_insn_uid++;
  1090.   XSTR (note, 3) = 0;
  1091.   XINT (note, 4) = subtype;
  1092.   add_insn_after (note, after);
  1093. }
  1094.  
  1095. /* Make an insn of code INSN with pattern PATTERN
  1096.    and add it to the end of the doubly-linked list.
  1097.    If PATTERN is a SEQUENCE, take the elements of it
  1098.    and emit an insn for each element.
  1099.  
  1100.    Returns the last insn emitted.  */
  1101.  
  1102. rtx
  1103. emit_insn (pattern)
  1104.      rtx pattern;
  1105. {
  1106.   rtx insn;
  1107.  
  1108.   if (GET_CODE (pattern) == SEQUENCE)
  1109.     {
  1110.       register int i;
  1111.       /* For an empty sequence, emit nothing.  */
  1112.       if (XVEC (pattern, 0))
  1113.     for (i = 0; i < XVECLEN (pattern, 0); i++)
  1114.       add_insn (insn = XVECEXP (pattern, 0, i));
  1115.     }
  1116.   else
  1117.     {
  1118.       insn = make_insn_raw (pattern, NULL);
  1119.       add_insn (insn);
  1120.     }
  1121.   return insn;
  1122. }
  1123.  
  1124. /* Emit the insns in a chain starting with INSN.  */
  1125.  
  1126. rtx
  1127. emit_insns (insn)
  1128.      rtx insn;
  1129. {
  1130.   while (insn)
  1131.     {
  1132.       rtx next = NEXT_INSN (insn);
  1133.       add_insn (insn);
  1134.       insn = next;
  1135.     }
  1136. }
  1137.  
  1138. /* Make an insn of code JUMP_INSN with pattern PATTERN
  1139.    and add it to the end of the doubly-linked list.  */
  1140.  
  1141. rtx
  1142. emit_jump_insn (pattern)
  1143.      rtx pattern;
  1144. {
  1145.   if (GET_CODE (pattern) == SEQUENCE)
  1146.     return emit_insn (pattern);
  1147.   else
  1148.     {
  1149.       register rtx insn = make_jump_insn_raw (pattern, NULL);
  1150.       add_insn (insn);
  1151.       return insn;
  1152.     }
  1153. }
  1154.  
  1155. /* Make an insn of code CALL_INSN with pattern PATTERN
  1156.    and add it to the end of the doubly-linked list.  */
  1157.  
  1158. rtx
  1159. emit_call_insn (pattern)
  1160.      rtx pattern;
  1161. {
  1162.   if (GET_CODE (pattern) == SEQUENCE)
  1163.     return emit_insn (pattern);
  1164.   else
  1165.     {
  1166.       register rtx insn = make_insn_raw (pattern, NULL);
  1167.       add_insn (insn);
  1168.       PUT_CODE (insn, CALL_INSN);
  1169.       return insn;
  1170.     }
  1171. }
  1172.  
  1173. /* Add the label LABEL to the end of the doubly-linked list.  */
  1174.  
  1175. rtx
  1176. emit_label (label)
  1177.      rtx label;
  1178. {
  1179.   /* This can be called twice for the same label
  1180.      as a result of the confusion that follows a syntax error!
  1181.      So make it harmless.  */
  1182.   if (INSN_UID (label) == 0)
  1183.     {
  1184.       INSN_UID (label) = cur_insn_uid++;
  1185.       add_insn (label);
  1186.     }
  1187.   return label;
  1188. }
  1189.  
  1190. /* Make an insn of code BARRIER
  1191.    and add it to the end of the doubly-linked list.  */
  1192.  
  1193. rtx
  1194. emit_barrier ()
  1195. {
  1196.   register rtx barrier = rtx_alloc (BARRIER);
  1197.   INSN_UID (barrier) = cur_insn_uid++;
  1198.   add_insn (barrier);
  1199.   return barrier;
  1200. }
  1201.  
  1202. /* Make an insn of code NOTE
  1203.    with data-fields specified by FILE and LINE
  1204.    and add it to the end of the doubly-linked list,
  1205.    but only if line-numbers are desired for debugging info.  */
  1206.  
  1207. rtx
  1208. emit_line_note (file, line)
  1209.      char *file;
  1210.      int line;
  1211. {
  1212.   emit_filename = file;
  1213.   emit_lineno = line;
  1214.  
  1215. #if 0
  1216.   if (no_line_numbers)
  1217.     return 0;
  1218. #endif
  1219.  
  1220.   return emit_note (file, line);
  1221. }
  1222.  
  1223. /* Make an insn of code NOTE
  1224.    with data-fields specified by FILE and LINE
  1225.    and add it to the end of the doubly-linked list.
  1226.    If it is a line-number NOTE, omit it if it matches the previous one.  */
  1227.  
  1228. rtx
  1229. emit_note (file, line)
  1230.      char *file;
  1231.      int line;
  1232. {
  1233.   register rtx note;
  1234.  
  1235.   if (line > 0)
  1236.     {
  1237.       if (file && last_filename && !strcmp (file, last_filename)
  1238.       && line == last_linenum)
  1239.     return 0;
  1240.       last_filename = file;
  1241.       last_linenum = line;
  1242.     }
  1243.  
  1244.   if (no_line_numbers && line > 0)
  1245.     {
  1246.       cur_insn_uid++;
  1247.       return 0;
  1248.     }
  1249.  
  1250.   note = rtx_alloc (NOTE);
  1251.   INSN_UID (note) = cur_insn_uid++;
  1252.   XSTR (note, 3) = file;
  1253.   XINT (note, 4) = line;
  1254.   add_insn (note);
  1255.   return note;
  1256. }
  1257.  
  1258. /* Emit a NOTE, and don't omit it even if LINE it the previous note.  */
  1259.  
  1260. rtx
  1261. emit_line_note_force (file, line)
  1262.      char *file;
  1263.      int line;
  1264. {
  1265.   last_linenum = -1;
  1266.   return emit_line_note (file, line);
  1267. }
  1268.  
  1269. /* Cause next statement to emit a line note even if the line number
  1270.    has not changed.  This is used at the beginning of a function.  */
  1271.  
  1272. void
  1273. force_next_line_note ()
  1274. {
  1275.   last_linenum = -1;
  1276. }
  1277.  
  1278. /* Return an indication of which type of insn should have X as a body.
  1279.    The value is CODE_LABEL, INSN, CALL_INSN or JUMP_INSN.  */
  1280.  
  1281. enum rtx_code
  1282. classify_insn (x)
  1283.      rtx x;
  1284. {
  1285.   if (GET_CODE (x) == CODE_LABEL)
  1286.     return CODE_LABEL;
  1287.   if (GET_CODE (x) == CALL)
  1288.     return CALL_INSN;
  1289.   if (GET_CODE (x) == RETURN)
  1290.     return JUMP_INSN;
  1291.   if (GET_CODE (x) == SET)
  1292.     {
  1293.       if (SET_DEST (x) == pc_rtx)
  1294.     return JUMP_INSN;
  1295.       else if (GET_CODE (SET_SRC (x)) == CALL)
  1296.     return CALL_INSN;
  1297.       else
  1298.     return INSN;
  1299.     }
  1300.   if (GET_CODE (x) == PARALLEL)
  1301.     {
  1302.       register int j;
  1303.       for (j = XVECLEN (x, 0) - 1; j >= 0; j--)
  1304.     if (GET_CODE (XVECEXP (x, 0, j)) == CALL)
  1305.       return CALL_INSN;
  1306.     else if (GET_CODE (XVECEXP (x, 0, j)) == SET
  1307.          && SET_DEST (XVECEXP (x, 0, j)) == pc_rtx)
  1308.       return JUMP_INSN;
  1309.     else if (GET_CODE (XVECEXP (x, 0, j)) == SET
  1310.          && GET_CODE (SET_SRC (XVECEXP (x, 0, j))) == CALL)
  1311.       return CALL_INSN;
  1312.     }
  1313.   return INSN;
  1314. }
  1315.  
  1316. /* Emit the rtl pattern X as an appropriate kind of insn.
  1317.    If X is a label, it is simply added into the insn chain.  */
  1318.  
  1319. void
  1320. emit (x)
  1321.      rtx x;
  1322. {
  1323.   enum rtx_code code = classify_insn (x);
  1324.  
  1325.   if (code == CODE_LABEL)
  1326.     emit_label (x);
  1327.   else if (code == INSN)
  1328.     emit_insn (x);
  1329.   else if (code == JUMP_INSN)
  1330.     {
  1331.       register rtx insn = emit_jump_insn (x);
  1332.       if (simplejump_p (insn) || GET_CODE (x) == RETURN)
  1333.     emit_barrier ();
  1334.     }
  1335.   else if (code == CALL_INSN)
  1336.     emit_call_insn (x);
  1337. }
  1338.  
  1339. /* Begin emitting insns to a sequence which can be packaged in an RTL_EXPR.
  1340.    Return an rtx containing data on any sequence already in progress.  */
  1341.  
  1342. rtx
  1343. start_sequence ()
  1344. {
  1345.   sequence_stack
  1346.     = gen_rtx (INSN_LIST, VOIDmode,
  1347.            first_insn, gen_rtx (INSN_LIST, VOIDmode,
  1348.                     last_insn, sequence_stack));
  1349.   first_insn = 0;
  1350.   last_insn = 0;
  1351.   return sequence_stack;
  1352. }
  1353.  
  1354. /* Set up the insn chain starting with FIRST
  1355.    as the current sequence, saving the previously current one.  */
  1356.  
  1357. void
  1358. push_to_sequence (first)
  1359.      rtx first;
  1360. {
  1361.   rtx last;
  1362.   for (last = first; last && NEXT_INSN (last); last = NEXT_INSN (last));
  1363.   sequence_stack
  1364.     = gen_rtx (INSN_LIST, VOIDmode,
  1365.            first_insn, gen_rtx (INSN_LIST, VOIDmode,
  1366.                     last_insn, sequence_stack));
  1367.   first_insn = first;
  1368.   last_insn = last;
  1369. }
  1370.  
  1371. /* After emitting to a sequence, restore previous saved state.
  1372.    The argument SAVED is no longer used.
  1373.  
  1374.    To get the contents of the sequence just made,
  1375.    you must call `gen_sequence' *before* calling here.  */
  1376.  
  1377. void
  1378. end_sequence (saved)
  1379.      rtx saved;
  1380. {
  1381.   first_insn = XEXP (sequence_stack, 0);
  1382.   last_insn = XEXP (XEXP (sequence_stack, 1), 0);
  1383.   sequence_stack = XEXP (XEXP (sequence_stack, 1), 1);
  1384. }
  1385.  
  1386. /* Generate a SEQUENCE rtx containing the insns already emitted
  1387.    to the current sequence.
  1388.  
  1389.    This is how the gen_... function from a DEFINE_EXPAND
  1390.    constructs the SEQUENCE that it returns.  */
  1391.  
  1392. rtx
  1393. gen_sequence ()
  1394. {
  1395.   rtx tem;
  1396.   rtvec newvec;
  1397.   int i;
  1398.   int len;
  1399.  
  1400.   /* Count the insns in the chain.  */
  1401.   len = 0;
  1402.   for (tem = first_insn; tem; tem = NEXT_INSN (tem))
  1403.     len++;
  1404.  
  1405.   /* For an empty sequence... */
  1406.   if (len == 0)
  1407.     return gen_rtx (SEQUENCE, VOIDmode, NULL);
  1408.  
  1409.   /* If only one insn, return its pattern rather than a SEQUENCE.  */
  1410.   if (len == 1
  1411.       && (GET_CODE (first_insn) == INSN
  1412.       || GET_CODE (first_insn) == JUMP_INSN
  1413.       || GET_CODE (first_insn) == CALL_INSN))
  1414.     return PATTERN (first_insn);
  1415.  
  1416.   /* Put them in a vector.  */
  1417.   newvec = rtvec_alloc (len);
  1418.   i = 0;
  1419.   for (tem = first_insn; tem; tem = NEXT_INSN (tem), i++)
  1420.     newvec->elem[i].rtx = tem;
  1421.  
  1422.   /* Make a SEQUENCE from this vector.  */
  1423.   return gen_rtx (SEQUENCE, VOIDmode, newvec);
  1424. }
  1425.  
  1426. /* Set up regno_reg_rtx, reg_rtx_no and regno_pointer_flag
  1427.    according to the chain of insns starting with FIRST.
  1428.  
  1429.    Also set cur_insn_uid to exceed the largest uid in that chain.
  1430.  
  1431.    This is used when an inline function's rtl is saved
  1432.    and passed to rest_of_compilation later.  */
  1433.  
  1434. static void restore_reg_data_1 ();
  1435.  
  1436. void
  1437. restore_reg_data (first)
  1438.      rtx first;
  1439. {
  1440.   register rtx insn;
  1441.   int i;
  1442.   register int max_uid = 0;
  1443.  
  1444.   for (insn = first; insn; insn = NEXT_INSN (insn))
  1445.     {
  1446.       if (INSN_UID (insn) >= max_uid)
  1447.     max_uid = INSN_UID (insn);
  1448.  
  1449.       switch (GET_CODE (insn))
  1450.     {
  1451.     case NOTE:
  1452.     case CODE_LABEL:
  1453.     case BARRIER:
  1454.       break;
  1455.  
  1456.     case JUMP_INSN:
  1457.     case CALL_INSN:
  1458.     case INSN:
  1459.       restore_reg_data_1 (PATTERN (insn));
  1460.       break;
  1461.     }
  1462.     }
  1463.  
  1464.   /* Don't duplicate the uids already in use.  */
  1465.   cur_insn_uid = max_uid + 1;
  1466.  
  1467.   /* If any regs are missing, make them up.  */
  1468.   for (i = FIRST_PSEUDO_REGISTER; i < reg_rtx_no; i++)
  1469.     if (regno_reg_rtx[i] == 0)
  1470.       regno_reg_rtx[i] = gen_rtx (REG, SImode, i);
  1471. }
  1472.  
  1473. static void
  1474. restore_reg_data_1 (orig)
  1475.      rtx orig;
  1476. {
  1477.   register rtx x = orig;
  1478.   register int i;
  1479.   register enum rtx_code code;
  1480.   register char *format_ptr;
  1481.  
  1482.   code = GET_CODE (x);
  1483.  
  1484.   switch (code)
  1485.     {
  1486.     case QUEUED:
  1487.     case CONST_INT:
  1488.     case CONST_DOUBLE:
  1489.     case SYMBOL_REF:
  1490.     case CODE_LABEL:
  1491.     case PC:
  1492.     case CC0:
  1493.     case LABEL_REF:
  1494.       return;
  1495.  
  1496.     case REG:
  1497.       if (REGNO (x) >= FIRST_PSEUDO_REGISTER)
  1498.     {
  1499.       /* Make sure regno_pointer_flag and regno_reg_rtx are large
  1500.          enough to have an element for this pseudo reg number.  */
  1501.       if (REGNO (x) >= reg_rtx_no)
  1502.         {
  1503.           reg_rtx_no = REGNO (x);
  1504.  
  1505.           if (reg_rtx_no >= regno_pointer_flag_length)
  1506.         {
  1507.           int newlen = max (regno_pointer_flag_length * 2,
  1508.                     reg_rtx_no + 30);
  1509.           rtx *new1;
  1510.           char *new = (char *) oballoc (newlen);
  1511.           bzero (new, newlen);
  1512.           bcopy (regno_pointer_flag, new, regno_pointer_flag_length);
  1513.  
  1514.           new1 = (rtx *) oballoc (newlen * sizeof (rtx));
  1515.           bzero (new1, newlen * sizeof (rtx));
  1516.           bcopy (regno_reg_rtx, new1, regno_pointer_flag_length * sizeof (rtx));
  1517.  
  1518.           regno_pointer_flag = new;
  1519.           regno_reg_rtx = new1;
  1520.           regno_pointer_flag_length = newlen;
  1521.         }
  1522.           reg_rtx_no ++;
  1523.         }
  1524.       regno_reg_rtx[REGNO (x)] = x;
  1525.     }
  1526.       return;
  1527.  
  1528.     case MEM:
  1529.       if (GET_CODE (XEXP (x, 0)) == REG)
  1530.     mark_reg_pointer (XEXP (x, 0));
  1531.       restore_reg_data_1 (XEXP (x, 0));
  1532.       return;
  1533.     }
  1534.  
  1535.   /* Now scan the subexpressions recursively.  */
  1536.  
  1537.   format_ptr = GET_RTX_FORMAT (code);
  1538.  
  1539.   for (i = 0; i < GET_RTX_LENGTH (code); i++)
  1540.     {
  1541.       switch (*format_ptr++)
  1542.     {
  1543.     case 'e':
  1544.       restore_reg_data_1 (XEXP (x, i));
  1545.       break;
  1546.  
  1547.     case 'E':
  1548.       if (XVEC (x, i) != NULL)
  1549.         {
  1550.           register int j;
  1551.  
  1552.           for (j = 0; j < XVECLEN (x, i); j++)
  1553.         restore_reg_data_1 (XVECEXP (x, i, j));
  1554.         }
  1555.       break;
  1556.     }
  1557.     }
  1558. }
  1559.  
  1560. /* Initialize data structures and variables in this file
  1561.    before generating rtl for each function.
  1562.    WRITE_SYMBOLS is nonzero if any kind of debugging info
  1563.    is to be generated.  */
  1564.  
  1565. void
  1566. init_emit (write_symbols)
  1567.      int write_symbols;
  1568. {
  1569.   first_insn = NULL;
  1570.   last_insn = NULL;
  1571.   sequence_stack = NULL;
  1572.   cur_insn_uid = 1;
  1573.   reg_rtx_no = FIRST_PSEUDO_REGISTER;
  1574.   last_linenum = 0;
  1575.   last_filename = 0;
  1576.   first_label_num = label_num;
  1577.  
  1578.   no_line_numbers = ! write_symbols;
  1579.   
  1580.   /* Init the tables that describe all the pseudo regs.  */
  1581.  
  1582.   regno_pointer_flag_length = FIRST_PSEUDO_REGISTER + 100;
  1583.  
  1584.   regno_pointer_flag 
  1585.     = (char *) oballoc (regno_pointer_flag_length);
  1586.   bzero (regno_pointer_flag, regno_pointer_flag_length);
  1587.  
  1588.   regno_reg_rtx 
  1589.     = (rtx *) oballoc (regno_pointer_flag_length * sizeof (rtx));
  1590.   bzero (regno_reg_rtx, regno_pointer_flag_length * sizeof (rtx));
  1591. }
  1592.  
  1593. /* Create some permanent unique rtl objects shared between all functions.  */
  1594.  
  1595. void
  1596. init_emit_once ()
  1597. {
  1598.   /* Create the unique rtx's for certain rtx codes and operand values.  */
  1599.  
  1600.   pc_rtx = gen_rtx (PC, VOIDmode);
  1601.   cc0_rtx = gen_rtx (CC0, VOIDmode);
  1602.  
  1603.   /* Don't use gen_rtx here since gen_rtx in this case
  1604.      tries to use these variables.  */
  1605.   const0_rtx = rtx_alloc (CONST_INT);
  1606.   INTVAL (const0_rtx) = 0;
  1607.   const1_rtx = rtx_alloc (CONST_INT);
  1608.   INTVAL (const1_rtx) = 1;
  1609.  
  1610.   fconst0_rtx = rtx_alloc (CONST_DOUBLE);
  1611.   dconst0_rtx = rtx_alloc (CONST_DOUBLE);
  1612. #ifdef APPLE_C
  1613.   /* Note that CONST_DOUBLE is misnamed, really means CONST_FLOAT, any size */
  1614.   ldconst0_rtx = rtx_alloc (CONST_DOUBLE);
  1615. #endif /* APPLE_C */
  1616.   {
  1617.     union real_extract u;
  1618. #ifdef REAL_IS_NOT_DOUBLE
  1619.     bzero (&u, sizeof u);
  1620.     u.d = REAL_VALUE_ATOF ("0");
  1621. #else
  1622.     u.d = 0;
  1623. #endif
  1624.  
  1625.     bcopy (&u, &CONST_DOUBLE_LOW (fconst0_rtx), sizeof u);
  1626.     CONST_DOUBLE_MEM (fconst0_rtx) = cc0_rtx;
  1627.     PUT_MODE (fconst0_rtx, SFmode);
  1628.  
  1629.     bcopy (&u, &CONST_DOUBLE_LOW (dconst0_rtx), sizeof u);
  1630.     CONST_DOUBLE_MEM (dconst0_rtx) = cc0_rtx;
  1631.     PUT_MODE (dconst0_rtx, DFmode);
  1632. #ifdef APPLE_C
  1633.     /* Make a long double zero rtx */
  1634.     bcopy (&u, &CONST_DOUBLE_LOW (ldconst0_rtx), sizeof u);
  1635.     CONST_DOUBLE_MEM (ldconst0_rtx) = cc0_rtx;
  1636.     PUT_MODE (ldconst0_rtx, XFmode);
  1637. #endif /* APPLE_C */
  1638.   }
  1639.  
  1640.   stack_pointer_rtx = gen_rtx (REG, Pmode, STACK_POINTER_REGNUM);
  1641.   frame_pointer_rtx = gen_rtx (REG, Pmode, FRAME_POINTER_REGNUM);
  1642. #ifdef STRUCT_VALUE
  1643.   struct_value_rtx = STRUCT_VALUE;
  1644. #else
  1645.   struct_value_rtx = gen_rtx (REG, Pmode, STRUCT_VALUE_REGNUM);
  1646. #endif
  1647.  
  1648. #ifdef STRUCT_VALUE_INCOMING
  1649.   struct_value_incoming_rtx = STRUCT_VALUE_INCOMING;
  1650. #else
  1651. #ifdef STRUCT_VALUE_INCOMING_REGNUM
  1652.   struct_value_incoming_rtx
  1653.     = gen_rtx (REG, Pmode, STRUCT_VALUE_INCOMING_REGNUM);
  1654. #else
  1655.   struct_value_incoming_rtx = struct_value_rtx;
  1656. #endif
  1657. #endif
  1658.  
  1659.   static_chain_rtx = gen_rtx (REG, Pmode, STATIC_CHAIN_REGNUM);
  1660.  
  1661. #ifdef STATIC_CHAIN_INCOMING_REGNUM
  1662.   if (STATIC_CHAIN_INCOMING_REGNUM != STATIC_CHAIN_REGNUM)
  1663.     static_chain_incoming_rtx = gen_rtx (REG, Pmode, STATIC_CHAIN_INCOMING_REGNUM);
  1664.   else
  1665. #endif
  1666.     static_chain_incoming_rtx = static_chain_rtx;
  1667.  
  1668.   if (FRAME_POINTER_REGNUM == ARG_POINTER_REGNUM)
  1669.     arg_pointer_rtx = frame_pointer_rtx;
  1670.   else
  1671.     arg_pointer_rtx = gen_rtx (REG, Pmode, ARG_POINTER_REGNUM);
  1672. }
  1673.